xfree( copy );
}
-int HexDigit( char hex ) {
- const char *Digits = "0123456789ABCDEF";
- const char *digits = "0123456789abcdef";
- char * ofs = strchr( digits, hex );
- if ( ofs ) {
- return ofs-digits;
- }
-
- ofs = strchr( Digits, hex );
- if ( ofs ) {
- return ofs-Digits;
- }
- return 0;
-}
-
-int HexByte( char* hex ) {
- int b = (HexDigit(hex[0])<<4)+HexDigit(hex[1]);
- return b;
-}
-
-void Init_Color( void ) {
- if ( opt_color[0] == '#' ) {
- opt_color_num = (HexByte( opt_color+1 )) + // red
- (HexByte( opt_color+3 )<<8) + // green
- (HexByte( opt_color+5 )<<16); // blue
- }
- else if ( !case_ignore_strcmp( opt_color, "aqua" ) ||
- !case_ignore_strcmp( opt_color, "cyan" )) {
- opt_color_num = 0xffff00;
- }
- else if ( !case_ignore_strcmp( opt_color, "black" )) {
- opt_color_num = 0x000000;
- }
- else if ( !case_ignore_strcmp( opt_color, "blue" )) {
- opt_color_num = 0xff0000;
- }
- else if ( !case_ignore_strcmp( opt_color, "fuchsia" ) ||
- !case_ignore_strcmp( opt_color, "magenta" )) {
- opt_color_num = 0xff00ff;
- }
- else if ( !case_ignore_strcmp( opt_color, "gray" )) {
- opt_color_num = 0x808080;
- }
- else if ( !case_ignore_strcmp( opt_color, "green" )) {
- opt_color_num = 0x008000;
- }
- else if ( !case_ignore_strcmp( opt_color, "lime" )) {
- opt_color_num = 0x00ff00;
- }
- else if ( !case_ignore_strcmp( opt_color, "maroon" )) {
- opt_color_num = 0x000080;
- }
- else if ( !case_ignore_strcmp( opt_color, "navy" )) {
- opt_color_num = 0x800000;
- }
- else if ( !case_ignore_strcmp( opt_color, "olive" )) {
- opt_color_num = 0x008080;
- }
- else if ( !case_ignore_strcmp( opt_color, "purple" )) {
- opt_color_num = 0x800080;
- }
- else if ( !case_ignore_strcmp( opt_color, "red" )) {
- opt_color_num = 0x0000ff;
- }
- else if ( !case_ignore_strcmp( opt_color, "silver" )) {
- opt_color_num = 0xc0c0c0;
- }
- else if ( !case_ignore_strcmp( opt_color, "teal" )) {
- opt_color_num = 0x808000;
- }
- else if ( !case_ignore_strcmp( opt_color, "white" )) {
- opt_color_num = 0xffffff;
- }
- else if ( !case_ignore_strcmp( opt_color, "yellow" )) {
- opt_color_num = 0x00ffff;
- }
- else {
- fatal( MYNAME ": unrecognized color name\n" );
- }
-}
-
static void
rd_init(const char *fname)
{
outfile = xfopen( fname, "wb", MYNAME );
Init_Output_Type();
Init_Road_Changes();
- Init_Color();
+ opt_color_num = color_to_bbggrr(opt_color);
Init_Wpt_Type();
if ( opt_zoom ) {
opt_zoom_num = atoi(opt_zoom);
*/
unsigned long get_crc32(const void * data, int datalen);
+/*
+ * Color helpers.
+ */
+int color_to_bbggrr(char *cname);
+
/*
* A constant for unknown altitude. It's tempting to just use zero
* but that's not very nice for the folks near sea level.
static char *snwhiteopt = NULL;
static char *snupperopt = NULL;
static char *snuniqueopt = NULL;
+static char *wptfgcolor = NULL;
+static char *wptbgcolor = NULL;
+
+
static
arglist_t ozi_args[] = {
NULL, ARGTYPE_BOOL},
{"snunique", &snuniqueopt, "Make synth. shortnames unique",
NULL, ARGTYPE_BOOL},
+ {"wptfgcolor", &wptfgcolor, "Waypoint foreground color",
+ "black", ARGTYPE_INT},
+ {"wptbgcolor", &wptbgcolor, "Waypoint background color",
+ "yellow", ARGTYPE_INT},
{0, 0, 0, 0, 0}
};
fsdata->fs.copy = (fs_copy) ozi_copy_fsdata;
fsdata->fs.destroy = ozi_free_fsdata;
- /* Provide reasonable defaults */
- fsdata->fgcolor = 0;
- fsdata->bgcolor = 65535;
+ /* Provide defaults via command line defaults */
+ fsdata->fgcolor = color_to_bbggrr(wptfgcolor);
+ fsdata->bgcolor = color_to_bbggrr(wptbgcolor);
return fsdata;
}
}
return result;
}
+
+/*
+ * Functions for converting human-readable colors to BBGGRR value.
+ * Substantial optimization opportunities remain.
+ */
+int HexDigit( char hex ) {
+ const char *Digits = "0123456789ABCDEF";
+ const char *digits = "0123456789abcdef";
+ char * ofs = strchr( digits, hex );
+ if ( ofs ) {
+ return ofs-digits;
+ }
+
+ ofs = strchr( Digits, hex );
+ if ( ofs ) {
+ return ofs-Digits;
+ }
+ return 0;
+}
+
+int HexByte( char* hex ) {
+ int b = (HexDigit(hex[0])<<4)+HexDigit(hex[1]);
+ return b;
+}
+
+/*
+ * Given an input of the form:
+ * #<hex number for RGB value>
+ * <decimal nummber for BBGGRR value>
+ * <color named in CSS1 spec>
+ * return the BBGGRR value for it.
+ */
+
+int
+color_to_bbggrr( char *opt_color )
+{
+ int color_num;
+ char *ep;
+
+ color_num = strtol(opt_color, &ep, 10);
+
+ if (ep != opt_color) {
+ return color_num;
+ }
+ else if ( opt_color[0] == '#' ) {
+ color_num = (HexByte( opt_color+1 )) + // red
+ (HexByte( opt_color+3 )<<8) + // green
+ (HexByte( opt_color+5 )<<16); // blue
+ }
+ else if ( !case_ignore_strcmp( opt_color, "aqua" ) ||
+ !case_ignore_strcmp( opt_color, "cyan" )) {
+ color_num = 0xffff00;
+ }
+ else if ( !case_ignore_strcmp( opt_color, "black" )) {
+ color_num = 0x000000;
+ }
+ else if ( !case_ignore_strcmp( opt_color, "blue" )) {
+ color_num = 0xff0000;
+ }
+ else if ( !case_ignore_strcmp( opt_color, "fuchsia" ) ||
+ !case_ignore_strcmp( opt_color, "magenta" )) {
+ color_num = 0xff00ff;
+ }
+ else if ( !case_ignore_strcmp( opt_color, "gray" )) {
+ color_num = 0x808080;
+ }
+ else if ( !case_ignore_strcmp( opt_color, "green" )) {
+ color_num = 0x008000;
+ }
+ else if ( !case_ignore_strcmp( opt_color, "lime" )) {
+ color_num = 0x00ff00;
+ }
+ else if ( !case_ignore_strcmp( opt_color, "maroon" )) {
+ color_num = 0x000080;
+ }
+ else if ( !case_ignore_strcmp( opt_color, "navy" )) {
+ color_num = 0x800000;
+ }
+ else if ( !case_ignore_strcmp( opt_color, "olive" )) {
+ color_num = 0x008080;
+ }
+ else if ( !case_ignore_strcmp( opt_color, "purple" )) {
+ color_num = 0x800080;
+ }
+ else if ( !case_ignore_strcmp( opt_color, "red" )) {
+ color_num = 0x0000ff;
+ }
+ else if ( !case_ignore_strcmp( opt_color, "silver" )) {
+ color_num = 0xc0c0c0;
+ }
+ else if ( !case_ignore_strcmp( opt_color, "teal" )) {
+ color_num = 0x808000;
+ }
+ else if ( !case_ignore_strcmp( opt_color, "white" )) {
+ color_num = 0xffffff;
+ }
+ else if ( !case_ignore_strcmp( opt_color, "yellow" )) {
+ color_num = 0x00ffff;
+ }
+ else {
+ fatal( "unrecognized color name %s\n", opt_color );
+ }
+
+ return color_num;
+}